def l977(nums):
    len1 = len(nums)
    left = 0
    right = len1-1
    res = []
    while left <= right:
        if nums[left]*nums[left] > nums[right]*nums[right]:
            res.append(nums[left]*nums[left])
            left += 1
        else:
            res.append(nums[right]*nums[right])
            right -= 1

    return res[::-1]
    pass

if __name__ =='__main__':
    print(l977([-4,-1,0,3,10]))
    print(l977([-7,-3,2,3,11]))
    pass